package com.gr.search;

public class LocationRecord {

    private float x;
    private float y;
    private int docID;
    private final static double EARTH_DIAMETER = 2 * 6378.2;
    private final static double PI = 3.14159265;
    private final static double RAD_CONVERT = PI / 180;

    public LocationRecord() {
    }

    public LocationRecord(float x, float y, int docID) {
        this.x = x;
        this.y = y;
        this.docID = docID;

    }

    public void setX(float x) {
        this.x = x;
    }

    public void setY(float y) {
        this.y = y;
    }

    public void setDocId(int docID) {
        this.docID = docID;
    }

    public float getX() {
        return this.x;
    }

    public float getY() {
        return this.y;
    }

    public int getDocID() {
        return this.docID;
    }

    public double distance(float lat, float lon) {
        double delta_lat, delta_lon;
        double temp;

        float lat1 = x;
        float lon1 = y;
        float lat2 = lat;
        float lon2 = lon;

        // convert degrees to radians
        lat1 *= RAD_CONVERT;
        lat2 *= RAD_CONVERT;

        // find the deltas
        delta_lat = lat2 - lat1;
        delta_lon = (lon2 - lon1) * RAD_CONVERT;

        // Find the great circle distance
        temp = Math.pow(Math.sin(delta_lat / 2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(delta_lon / 2), 2);
        return EARTH_DIAMETER * Math.atan2(Math.sqrt(temp), Math.sqrt(1 - temp));
    }
}
